Repository navigation
Startup ordering - #397
Startup ordering#397rwb27 wants to merge 11 commits into
Conversation
370fec2 to
34deb08
Compare
34deb08 to
94348ce
Compare
This comment was marked as outdated.
This comment was marked as outdated.
374df1a to
7206548
Compare
Dogmans
left a comment
There was a problem hiding this comment.
Implementation in the loop makes sense, only suggestion is maybe require_started=True rather than deferred possibly.
Thanks - I've wavered a bit on what to call it: naming things is hard. I previously called it Thinking about it, maybe As you can see, I've thought about it and I've not come to a strong conclusion... |
Also, `attributes` is never used. I've merged it with `class_attributes` to reduce pointless duplication.
This commit adds a `start_first` attribute to `lt.thing_slot` and a simple algorithm that determines the order in which things must be started in order to fulfil those constraints. It's not guaranteed to work, and will give a helpful error if that happens.
This should check that Things get ordered correctly.
Non-deferred Thing Slots now ignore dependencies on the host Thing. This is most likely to happen with a Thing Slot typed as `lt.Thing` which matches all Things on a server. I've added a test for this.
This gets mypy passing again (some failures appeared when I rebased due to a mypy upgrade).
This adds tests that cover: * the startup order not matching the server's `things`. * every case of `_connected_thing_names`, including no thing connected.
This implements @bprobert97's suggestion to preserve the order of the dictionary keys if there are no other constraints. This mostly involved swapping some sets for lists. I realised that preserving the dict order really helps with the tests. I can repeat tests with the dict keys in different orders, and check that the order is preserved when there are no constraints, but fixed when there's a constraint.
7206548 to
807ad72
Compare
The argument used to affect start up order was previously `start_first`, then `deferred`. I'm going to revert to `start_before` as it is less confusing. This commit updates the code and docs to reflect that. I've checked the docs and done some searches to try to catch the inconsistencies.
807ad72 to
3638c11
Compare
|
I've changed the argument to |
| in which things will be started: it's assumed the slot will not be | ||
| accessed until all Things have started. | ||
|
|
||
| If `start_before` is set to `False` then LabThings |
There was a problem hiding this comment.
| If `start_before` is set to `False` then LabThings | |
| If `start_before` is set to `True` then LabThings |
| in which things will be started: it's assumed the slot will not be | ||
| accessed until all Things have started. | ||
|
|
||
| If `start_before` is set to `False` then LabThings |
There was a problem hiding this comment.
| If `start_before` is set to `False` then LabThings | |
| If `start_before` is set to `True` then LabThings |
|
|
||
|
|
||
| def test_start_before_default(): | ||
| """Check that the default value of `start_before` is True.""" |
There was a problem hiding this comment.
| """Check that the default value of `start_before` is True.""" | |
| """Check that the default value of `start_before` is False.""" |
| ({"b": ThingThree, "a": ThingWithoutDependency}, {("b", "a")}), | ||
| # If start_before==True, the list order can take only one value | ||
| ({"a": ThingWithDependency, "b": ThingThree}, {("b", "a")}), | ||
| ({"b": ThingThree, "a": ThingWithoutDependency}, {("b", "a")}), |
There was a problem hiding this comment.
| ({"b": ThingThree, "a": ThingWithoutDependency}, {("b", "a")}), | |
| ({"b": ThingThree, "a": ThingWithDependency}, {("b", "a")}), |
There was a problem hiding this comment.
({"b": ThingThree, "a": ThingWithoutDependency}, {("b", "a")}) is already a test case on line 564
This PR allows
Things to specify that some Thing Slots must be started first. That means the connected Thing will already be running when__enter__is called on the host Thing. This should make it easier to write code that interacts with other Things on start-up.The new syntax looks like the example in #388:
Without
start_before=Truethere is no guarantee thatself.wrappedhas started up, so the function call in__enter__may or may not work.Things to do before merge:
deferred=Falseinstead ofstart_first=Trueto enable this behaviour.Closes #388